#ifndef SERVERLIVEINFO_H
#define SERVERLIVEINFO_H
#include "libs/core/model/liveinfo.h"
#include <QJsonObject>
#include <QString>

struct ServerLiveInfo
{
    int id;
    QString platform_id;
    QString platform_web_rid;
    int owner;
    int presenter;
    int total_user_count;
    int user_count;
    int view_count;
    int like_count;
    QString stream_url;
    QString web_stream_url;
    QString title;
    QString qrcode_url;
    int status;
    QDateTime update_time;
    int updater;

    yc::LiveInfo toLiveInfo() const
    {
        return yc::LiveInfo { id,
                              platform_id,
                              platform_web_rid,
                              owner,
                              presenter,
                              total_user_count,
                              user_count,
                              view_count,
                              like_count,
                              yc::StreamUrl::fromJson(stream_url),
                              yc::StreamUrl::fromJson(web_stream_url),
                              title,
                              qrcode_url,
                              status,
                              update_time,
                              updater };
    }

    static ServerLiveInfo fromLiveInfo(const yc::LiveInfo& li)
    {
        return ServerLiveInfo { li.id,
                                li.platform_id,
                                li.platform_web_rid,
                                li.owner,
                                li.presenter,
                                li.total_user_count,
                                li.user_count,
                                li.view_count,
                                li.like_count,
                                li.stream_url.toJson(),
                                li.web_stream_url.toJson(),
                                li.title,
                                li.qrcode_url,
                                li.status,
                                li.update_time,
                                li.updater };
    }

    QJsonObject toJsonObject() const
    {
        return QJsonObject { { "id", id },
                             { "platformId", platform_id },
                             { "platformWebRid", platform_web_rid },
                             { "owner", owner },
                             { "presenter", presenter },
                             { "totalUserCount", total_user_count },
                             { "userCount", user_count },
                             { "viewCount", view_count },
                             { "likeCount", like_count },
                             { "streamUrl", stream_url },
                             { "webStreamUrl", web_stream_url },
                             { "title", title },
                             { "qrcodeUrl", qrcode_url },
                             { "status", status },
                             { "updateTime", update_time.toString(Qt::ISODate) },
                             { "updater", updater } };
    }

    static ServerLiveInfo fromJsonObject(const QJsonObject& jo)
    {
        return ServerLiveInfo { jo["id"].toInt(),
                                jo["platformId"].toString(),
                                jo["platformWebRid"].toString(),
                                jo["owner"].toInt(),
                                jo["presenter"].toInt(),
                                jo["totalUserCount"].toInt(),
                                jo["userCount"].toInt(),
                                jo["viewCount"].toInt(),
                                jo["likeCount"].toInt(),
                                jo["streamUrl"].toString(),
                                jo["webStreamUrl"].toString(),
                                jo["title"].toString(),
                                jo["qrcodeUrl"].toString(),
                                jo["status"].toInt(yc::LiveStatus::INACTIVE_LIVE_STATUS),
                                QDateTime::fromString(jo["updateTime"].toString(), Qt::ISODate),
                                jo["updater"].toInt() };
    }
};

#endif // SERVERLIVEINFO_H
